package com.magicsoft.share.presenter.main;

import android.util.Log;

import com.magicsoft.share.base.BasePresenter;
import com.magicsoft.share.bean.main.SMSCode;
import com.magicsoft.share.constant.APIService;
import com.magicsoft.share.rx_retrofit_network.location.retrofit.RetrofitUtil;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.LoadingTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.NetWorkTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.SimpleObserver;
import com.magicsoft.share.view.main.ISMSVerificationView;


/**
 * Created by lyf on 2017/11/15/015.
 */

public class SMSVerificationPresenter extends BasePresenter<ISMSVerificationView> {
    public void sendCode(String method, String mobile) {
        Log.d("sms", "sendCode: ");
        RetrofitUtil.getApi(APIService.class).
                sendCode(method, mobile).
                compose(new NetWorkTransformer<SMSCode>()).
                compose(new LoadingTransformer<SMSCode>(mContext)).
                subscribe(new SimpleObserver<SMSCode>(mCompositeDisposable) {
                    @Override
                    public void call(SMSCode smsCode) {
                        getView().sendCodeSuccess(smsCode);

                    }
                });
    }

    public void checkSMSCode(String mobile, String code,String method) {
        RetrofitUtil.getApi(APIService.class).checkSmsCode(mobile, code,method).
                compose(new NetWorkTransformer()).
                compose(new LoadingTransformer(mContext)).
                subscribe(new SimpleObserver(mCompositeDisposable) {

                    @Override
                    public void call( Object o) {

                        getView().checkSMSCodeSuccess();
                    }
                    @Override
                    public void showErrorMsg(Throwable e, String errorMsg) {

                        getView().checkSMSCodeFail( errorMsg);
                    }


                });

    }
}
